from django.shortcuts import render

# Create your views here.
from django.views import View

from apps.contents.models import ContentCategory
from apps.contents.utils import get_categories



class IndexView(View):
    def get(self,request):
        #显示商品三级分类
        categories = get_categories()

        #显示广告
        ad_categories = ContentCategory.objects.all()
        contents = {}
        for ad in ad_categories:
            contents[ad.key] = ad.content_set.filter(status = True).order_by('sequence')

        context = {
            'categories':categories,
            'contents':contents
        }
        return render(request, 'index.html', context)